package DoublePointer;

import Utils.ListNode;

// Lettcode 141: https://leetcode-cn.com/problems/linked-list-cycle/
public class hasCycle {
    public boolean hasCycle(ListNode head) {
        if (head == null) {
            return false;
        }
        ListNode slowPoint = head;
        ListNode fastPoint = head.next;
        while (slowPoint != null && fastPoint != null && fastPoint.next != null) {
            if (slowPoint.next == fastPoint.next) {
                return true;
            }
            slowPoint = slowPoint.next;
            fastPoint = fastPoint.next.next;
        }
        return false;
    }
}
